<template>


        <div class="super_container">



                <!-- Home -->

                <!--包含头部和左侧菜单-->

                <myheader></myheader>



               <div class="boxes">
                    <div class="section_container">
                        <div class="container">
                          <div align='center'><h1>登陆</h1></div>
                          <!-- <el-form-item label="请激活账户">
                            <el-button v-on:click='is_active'>激活</el-button>
                          </el-form-item> -->

                          <el-input placeholder="请输入用户名" v-model="account"></el-input>
                          <el-input type='password' placeholder="请输入密码" v-model="password"></el-input>
                          
                          <el-button v-on:click='getApiData_post'>login</el-button>
                          
                          <el-button><router-link :to="'register'">注册</router-link></el-button>
                          
                          <img src="../assets/images/微博.jpg" style="width:50px; margin-right:0px;" v-on:click='get_sina()'> 
                          <img src="../assets/images/QQ.jpg" style="width:50px; margin-right:0px;" v-on:click='tologin()'> 
                          
                          
                          
                        </div>
                    </div>
                </div>





                <myfooter></myfooter>


            </div>


</template>



      <script>



        import myheader from './header.vue'
        import myfooter from './footer.vue'
        import Cookies from 'js-cookie'

      export default {
        data () {
          return {
            labelPosition: 'right',
            msg: "这是一个变量",
            account:'',
            password:'',
            dataList:[],
            clicked:0,
            upath: '',
            result: '',
            uping:0
            }
          },
          components: {
          'myheader':myheader,
          'myfooter':myfooter
          },
          mounted:function(){

              this.common.get_menu();

        },
          methods:{
              changetest(index){
                  this.clicked = index;
              },  
              //定义异步post方法
              getApiData_post:function(){
              //定义url
              let url =  this.base_url +'/user/login';
              //定义中介
              var _this = this;
              var data = {
                'account' :_this.account,
                'password' :_this.password,
              }
              //使用axios发送异步请求
              this.axios.post(url,this.qs.stringify(data))
                .then(function(result){
                  _this.data = result.data;
                  console.log(_this.data);
                  _this.code = result.data.code;
                  if(_this.code == 200){
                    var user_id = result.data.user_id
                    localStorage.setItem('token',result.data.token)
                    Cookies.set('username', _this.account,{ expires: 7 })
                    Cookies.set('user_id', user_id,{ expires: 7 })
                    alert('登录成功')
                    _this.$router.push('/')
                  }
                  })
                },
                get_sina:function(){
                  //定义url
                  let url = this.base_url + '/user/sina';
                  //定义中介
                  let _this = this;
                  //使用axios发送异步请求
                  _this.axios.get(url)
                  .then(function(result){
                    if (result.status == 200){
                      console.log(result.data)
                      window.location.href = result.data
                    }
                  });
                },
                tologin:function(){
                  let url = this.base_url + '/get_qqcode'
                  console.log(url)
                  let _this = this;
                   _this.axios.get(url)
                   .then(function(result){
                     console.log(result.data.message)
                     window.location.href = result.data.message
                   })
                }
                }
      }
      

      </script>

      <style>



      </style>
